﻿using System.Web.Mvc;
using System.Web.Routing;
using lindyaka.Models.Administration;
using UserAccountRoles = lindyaka.Services.Administration.UserAccountRoles;

namespace lindyaka.Web.Areas.Administration.Controllers
{
    public class UserAccountRolesController : Controller
    {
        private readonly UserAccountRoles _userAccountRoles;

        public UserAccountRolesController()
        {
            _userAccountRoles = new UserAccountRoles();
        }

        //
        // GET: /Administration/UserAccountRoles/

        public ActionResult Index(int id)
        {
            return View(_userAccountRoles.Get(id));
        }

        //
        // GET: /Administration/UserAccountRoles/Create

        public ActionResult Create(int id)
        {
            return View(_userAccountRoles.GetWithRoles(id));
        }

        //
        // POST: /Administration/UserAccountRoles/Create

        [HttpPost]
        public ActionResult Create(int id, FormCollection collection)
        {
            var associateRole = new UserAccountAssociateRoles();
            TryUpdateModel(associateRole);
            if (ModelState.IsValid)
            {
                associateRole.UserAccountId = id;
                _userAccountRoles.Add(associateRole);
                return RedirectToAction(string.Empty, "UserAccountRoles", new { id = associateRole.UserAccountId });
            }
            return View(_userAccountRoles.GetWithRoles(id));
        }

        //
        // GET: /Administration/UserAccountRoles/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Administration/UserAccountRoles/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}